﻿/* QF classbuilder for Enlib */
using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Logging;

#region SYS_RoleFunction实体类
public class SYS_RoleFunction
{
	private string m_RoleID;
	private string m_FunctionID;
	
	public SYS_RoleFunction ()
	{
		m_RoleID="";
		m_FunctionID="";
	}
	
	public string RoleID
	{
		get{return m_RoleID;}
		set{m_RoleID=value;}
	}
	public string FunctionID
	{
		get{return m_FunctionID;}
		set{m_FunctionID=value;}
	}
}
#endregion

#region SYS_RoleFunction管理类
public partial class LogicLayer
{
	public bool AddSYS_RoleFunction(SYS_RoleFunction theSYS_RoleFunction)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "insert into SYS_RoleFunction (RoleID,FunctionID) values (@RoleID,@FunctionID)";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			db.AddInParameter(cmd, "@RoleID", DbType.String, theSYS_RoleFunction.RoleID);
			db.AddInParameter(cmd, "@FunctionID", DbType.String, theSYS_RoleFunction.FunctionID);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("AddSYS_RoleFunction:" + ex.Message );
			return false;
		}
	}
	
	public SYS_RoleFunction GetSYS_RoleFunctionFromDataReader(IDataReader dataReader)
	{
		try
		{
			SYS_RoleFunction result = new SYS_RoleFunction();
			
			if (dataReader["RoleID"] != null && dataReader["RoleID"] != System.DBNull.Value )
				result.RoleID = (string)dataReader["RoleID"];
			if (dataReader["FunctionID"] != null && dataReader["FunctionID"] != System.DBNull.Value )
				result.FunctionID = (string)dataReader["FunctionID"];
			
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("GetReaderSYS_RoleFunction:" + ex.Message);
			return null;
		}
	}
	
	public SYS_RoleFunction GetSYS_RoleFunction(string RoleID,string FunctionID)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "select * From SYS_RoleFunction where RoleID=@RoleID and FunctionID=@FunctionID";
			
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			db.AddInParameter(cmd, "@RoleID", DbType.String, RoleID);
			db.AddInParameter(cmd, "@FunctionID", DbType.String, FunctionID);
			
			SYS_RoleFunction result = null;
			using (IDataReader dataReader = db.ExecuteReader(cmd))
			{
				if (dataReader.Read())
				{
					result = GetSYS_RoleFunctionFromDataReader( dataReader );
				}
			}
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("GetSYS_RoleFunction:" + ex.Message);
			return null;
		}
	}
	
	public bool DelSYS_RoleFunction(string RoleID,string FunctionID)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "delete From SYS_RoleFunction where RoleID=@RoleID and FunctionID=@FunctionID";
			
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			db.AddInParameter(cmd, "@RoleID", DbType.String, RoleID);
			db.AddInParameter(cmd, "@FunctionID", DbType.String, FunctionID);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("DelSYS_RoleFunction:" + ex.Message);
			return false;
		}
	}
	
	public bool UpdateSYS_RoleFunction(SYS_RoleFunction theSYS_RoleFunction)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "update SYS_RoleFunction set  where RoleID=@RoleID and FunctionID=@FunctionID";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			db.AddInParameter(cmd, "@RoleID", DbType.String, theSYS_RoleFunction.RoleID);
			db.AddInParameter(cmd, "@FunctionID", DbType.String, theSYS_RoleFunction.FunctionID);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("UpdateSYS_RoleFunction:" + ex.Message);
			return false;
		}
	}
	
	public List<SYS_RoleFunction> ListSYS_RoleFunction()
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "select * from SYS_RoleFunction";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			 List<SYS_RoleFunction> result = new  List<SYS_RoleFunction>();
			using (IDataReader dataReader = db.ExecuteReader(cmd))
			{
				while (dataReader.Read())
				{
					SYS_RoleFunction obj = GetSYS_RoleFunctionFromDataReader( dataReader );
					if(obj != null)
						result.Add(obj);
				}
			}
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("ListSYS_RoleFunction:" + ex.Message);
			return null;
		}
	}
	
}
#endregion